package com.tpp.baseConsumer.controller;

import com.tpp.baseConsumer.mapper.AreaMapper;
import com.tpp.baseConsumer.service.AdminAreaService;
import com.tpp.comm.pojo.TpArea;
import com.tpp.comm.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/s/area")
@Slf4j
public class AdminAreaController {

    @Resource
    private AdminAreaService adminAreaService;

    @GetMapping("/findArea")
    public Result findArea(){
        return Result.success(adminAreaService.findArea());
    }

    @PostMapping("/add")
    public Result addArea(@RequestBody TpArea tpArea){
        try {
            adminAreaService.addArea(tpArea);
            return Result.success("添加成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.fail("添加失败");
        }
    }

    @PostMapping("/update")
    public Result updateArea(@RequestBody TpArea tpArea){
        try {
            adminAreaService.updateArea(tpArea);
            return Result.success("修改成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.fail("修改失败");
        }
    }

    @GetMapping("/delete")
    public Result deleteArea(Long id){
        try {
            adminAreaService.deleteArea(id);
            return Result.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.fail("删除失败");
        }
    }

    @GetMapping("/findById")
    public Result findById(Long id){
        return Result.success(adminAreaService.findById(id));
    }
}
